//
//  SAStaffManagementCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/2.
//

#import "SAStaffManagementCell.h"
#import "SAStaffManagementModel.h"

@interface SAStaffManagementCell ()

@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *iphoneLab;
@property (nonatomic, strong) UIButton *setBtn;

@end

@implementation SAStaffManagementCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAStaffManagementModel *)model {
    _model = model;
    _typeLab.text = @"";
    self.setBtn.hidden = NO;
    
    if ([model.empType isEqualToString:@"1"]) {
        _typeLab.text = @"老板";
        self.setBtn.hidden = YES;
    }else if([model.empType isEqualToString:@"2"]) {
        _typeLab.text = @"店长";
    }else if([model.empType isEqualToString:@"3"]) {
        _typeLab.text = @"营业员";
    }else if([model.empType isEqualToString:@"4"]) {
        _typeLab.text = @"收银员";
    }
    _nameLab.text = model.empName;
    if (model.mobile.length == 0) {
        _iphoneLab.text = @"";
    }else {
        _iphoneLab.text = model.mobile;
    }
    
    if ([model.empId isEqualToString:[SAValueManger shareInStance].userInfo.empId]) {
        self.setBtn.hidden = YES;
    }
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *modifyEmp = [NSString stringWithFormat:@"%@",menuList[9][@"perms"][@"modifyEmp"]];
    if ([modifyEmp isEqualToString:@"1"]) {
        self.setBtn.hidden = YES;
    }
}

-(void)clickedSetBtn {
    !self.setBlock ?: self.setBlock();
}

-(void)initUI {
    self.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.typeLab];
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.iphoneLab];
    [self.contentView addSubview:self.setBtn];
}

-(UILabel *)typeLab {
    if (!_typeLab) {
        _typeLab = [[UILabel alloc] initWithFrame:SARectMake(30, 14, 42, 42)];
        _typeLab.textColor = kPinkColor;
        _typeLab.font = kFont(12);
        _typeLab.layer.cornerRadius = kScaleNum(21);
        _typeLab.layer.masksToBounds = YES;
        _typeLab.textAlignment = NSTextAlignmentCenter;
        _typeLab.layer.borderWidth = kScaleNum(1);
        _typeLab.layer.borderColor = kPinkColor.CGColor;
    }
    return _typeLab;
}

-(UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] initWithFrame:SARectMake(82, 14, 260, 20)];
        _nameLab.textColor = kBlackColor;
        _nameLab.font = kFont(15);
    }
    return _nameLab;
}

-(UILabel *)iphoneLab {
    if (!_iphoneLab) {
        _iphoneLab = [[UILabel alloc] initWithFrame:SARectMake(82, 36, 260, 20)];
        _iphoneLab.textColor = kLightgGrayColor;
        _iphoneLab.font = kFont(15);
    }
    return _iphoneLab;
}

-(UIButton *)setBtn {
    if (!_setBtn) {
        _setBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _setBtn.frame = SARectMake(265, 20, 80, 30);
        _setBtn.backgroundColor = kBuleColor;
        [_setBtn setTitle:@"权限设置" forState:UIControlStateNormal];
        [_setBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _setBtn.titleLabel.font = kFont(16);
        _setBtn.layer.cornerRadius = kScaleNum(5);
        _setBtn.layer.masksToBounds = YES;
        [_setBtn addTarget:self action:@selector(clickedSetBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _setBtn;
}

@end
